package com.med.controller;

import com.med.service.INoticeService;
import com.med.vo.NoticeVO;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Project:internet-based-healthcare
 * Package:com.med.controller
 *
 * @Description:
 * @Author:其一
 * @CreateTime: 2025-08-18-11-53
 */
@RestController
@RequestMapping("/notice")
public class NoticeController extends BaseController {
    @Autowired
    private INoticeService noticeService;

    //查询通知列表
    @GetMapping("/list")
    public TableDataInfo list(NoticeVO noticeVO) {
        startPage();
        List<NoticeVO> noticePage = noticeService.getNoticePage(noticeVO);
        return getDataTable(noticePage);
    }

    //修改为已读
    @PostMapping("/read/{noticeId}")
    public AjaxResult read(@PathVariable Integer noticeId) {
        return toAjax(noticeService.markAsRead(noticeId) ? 1 : 0);
    }

    //查询未读数量
    @GetMapping("/unreadCount")
    public AjaxResult unreadCount(@RequestParam Integer noticeType) {
        return AjaxResult.success(noticeService.getUnreadCount(noticeType));
    }
}
